<?php

/**
 * This is the model class for table "account".
 *
 * The followings are the available columns in table 'account':
 * @property integer $uid
 * @property string $email
 * @property string $password
 * @property string $name
 * @property string $createTime
 * @property string $username
 * @property string $id_type
 * @property string $facebook
 * @property string $lang
 * @property integer $confirm_email
 * @property integer $confirm_phone
 * @property string $picture
 *
 * The followings are the available model relations:
 * @property AccountToken[] $accountTokens
 */
class Account extends ActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Account the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'account';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('confirm_email, confirm_phone', 'numerical', 'integerOnly'=>true),
			array('email, password, name, username', 'length', 'max'=>45),
			array('id_type', 'length', 'max'=>50),
			array('facebook, picture', 'length', 'max'=>255),
			array('lang', 'length', 'max'=>5),
			array('createTime', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('uid, email, password, name, createTime, username, id_type, facebook, lang, confirm_email, confirm_phone, picture', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'accountTokens' => array(self::HAS_MANY, 'AccountToken', 'uid'),
            'accountDetail' => array(self::BELONGS_TO, 'AccountDetail', 'uid'),
			'place' => array(self::HAS_ONE, 'Place', 'owner_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'uid' => 'Uid',
			'email' => 'Email',
			'password' => 'Password',
			'name' => 'Name',
			'createTime' => 'Create Time',
			'username' => 'Username',
			'id_type' => 'Id Type',
			'facebook' => 'Facebook',
			'lang' => 'Lang',
			'confirm_email' => 'Confirm Email',
			'confirm_phone' => 'Confirm Phone',
			'picture' => 'Picture',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('uid',$this->uid);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('createTime',$this->createTime,true);
		$criteria->compare('username',$this->username,true);
		$criteria->compare('id_type',$this->id_type,true);
		$criteria->compare('facebook',$this->facebook,true);
		$criteria->compare('lang',$this->lang,true);
		$criteria->compare('confirm_email',$this->confirm_email);
		$criteria->compare('confirm_phone',$this->confirm_phone);
		$criteria->compare('picture',$this->picture,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}